# -*- coding: utf-8 -*-
# @Time : 2022/6/13 9:54
# @Author : WangYunfei
# @FileName: 多线程.py
# @Email: yunfei.wang@innvote.com
# import threading
# from time import sleep, ctime
#
# loops = (4, 2)
#
#
# class MyThread(threading.Thread):
#     def __init__(self, target, args):
#         super().__init__()
#         self.target = target
#         self.args = args
#
#     def run(self):
#         self.target(*self.args)
#
#
# def loop(nloop, nsec):
#     print(ctime(), 'start loop', nloop)
#     sleep(nsec)
#     print(ctime(), 'end loop', nloop)
#
#
# def main():
#     threads = []
#     nloops = range(len(loops))
#
#     for i in nloops:
#         t = MyThread(loop, (i, loops[i]))
#         threads.append(t)
#
#     for i in nloops:
#         threads[i].start()
#
#     for i in nloops:
#         threads[i].join()
#
#
# if __name__ == "__main__":
#     main()
import time
from concurrent.futures import ThreadPoolExecutor
import requests


def crawl(url):
    res = requests.get(url)
    print(res)


if __name__ == '__main__':
    base_url = 'https://cs.fang.lianjia.com/loupan/pg{}/?_t=1/'
    start = time.time()
    with ThreadPoolExecutor(10) as f:
        for i in range(1,15):
            f.submit(crawl,url=base_url.format(i))
    for i in range(1, 15):
        crawl(url=base_url.format(i))
    end_time = time.time() - start
    print(end_time, '结束时间')
